home *** CD-ROM | disk | FTP | other *** search
/ Languguage OS 2 / Languguage OS II Version 10-94 (Knowledge Media)(1994).ISO / gnu / dejagnu.lha / dejagnu-1.0.1 / tcl / tests / string.test < prev    next >
Text File  |  1992-11-06  |  10KB  |  323 lines

  1. # Commands covered:  string
  2. #
  3. # This file contains a collection of tests for one or more of the Tcl
  4. # built-in commands.  Sourcing this file into Tcl runs the tests and
  5. # generates output for errors.  No output means no errors were found.
  6. #
  7. # Copyright 1991 Regents of the University of California
  8. # Permission to use, copy, modify, and distribute this
  9. # software and its documentation for any purpose and without
  10. # fee is hereby granted, provided that this copyright notice
  11. # appears in all copies.  The University of California makes no
  12. # representations about the suitability of this software for any
  13. # purpose.  It is provided "as is" without express or implied
  14. # warranty.
  15. #
  16. # $Header: /user6/ouster/tcl/tests/RCS/string.test,v 1.6 92/07/02 08:50:33 ouster Exp $ (Berkeley)
  17.  
  18. if {[string compare test [info procs test]] == 1} then {source defs}
  19.  
  20. test string-1.1 {string compare} {
  21.     string compare abcde abdef
  22. } -1
  23. test string-1.2 {string compare} {
  24.     string c abcde ABCDE
  25. } 1
  26. test string-1.3 {string compare} {
  27.     string compare abcde abcde
  28. } 0
  29. test string-1.4 {string compare} {
  30.     list [catch {string compare a} msg] $msg
  31. } {1 {wrong # args: should be "string compare string1 string2"}}
  32. test string-1.5 {string compare} {
  33.     list [catch {string compare a b c} msg] $msg
  34. } {1 {wrong # args: should be "string compare string1 string2"}}
  35.  
  36. test string-2.1 {string first} {
  37.     string first bq abcdefgbcefgbqrs
  38. } 12
  39. test string-2.2 {string first} {
  40.     string fir bcd abcdefgbcefgbqrs
  41. } 1
  42. test string-2.3 {string first} {
  43.     string f b abcdefgbcefgbqrs
  44. } 1
  45. test string-2.4 {string first} {
  46.     string first xxx x123xx345xxx789xxx012
  47. } 9
  48. test string-2.5 {string first} {
  49.     list [catch {string first a} msg] $msg
  50. } {1 {wrong # args: should be "string first string1 string2"}}
  51. test string-2.6 {string first} {
  52.     list [catch {string first a b c} msg] $msg
  53. } {1 {wrong # args: should be "string first string1 string2"}}
  54.  
  55. test string-3.1 {string index} {
  56.     string index abcde 0
  57. } a
  58. test string-3.2 {string index} {
  59.     string i abcde 4
  60. } e
  61. test string-3.3 {string index} {
  62.     string index abcde 5
  63. } {}
  64. test string-3.4 {string index} {
  65.     list [catch {string index abcde -10} msg] $msg
  66. } {0 {}}
  67. test string-3.5 {string index} {
  68.     list [catch {string index} msg] $msg
  69. } {1 {wrong # args: should be "string index string charIndex"}}
  70. test string-3.6 {string index} {
  71.     list [catch {string index a b c} msg] $msg
  72. } {1 {wrong # args: should be "string index string charIndex"}}
  73. test string-3.7 {string index} {
  74.     list [catch {string index a xyz} msg] $msg
  75. } {1 {expected integer but got "xyz"}}
  76.  
  77. test string-4.1 {string last} {
  78.     string la xxx xxxx123xx345x678
  79. } 1
  80. test string-4.2 {string last} {
  81.     string last xx xxxx123xx345x678
  82. } 7
  83. test string-4.3 {string last} {
  84.     string las x xxxx123xx345x678
  85. } 12
  86. test string-4.4 {string last} {
  87.     list [catch {string last a} msg] $msg
  88. } {1 {wrong # args: should be "string last string1 string2"}}
  89. test string-4.5 {string last} {
  90.     list [catch {string last a b c} msg] $msg
  91. } {1 {wrong # args: should be "string last string1 string2"}}
  92.  
  93. test string-5.1 {string length} {
  94.     string length "a little string"
  95. } 15
  96. test string-5.2 {string length} {
  97.     string le ""
  98. } 0
  99. test string-5.3 {string length} {
  100.     list [catch {string length} msg] $msg
  101. } {1 {wrong # args: should be "string length string"}}
  102. test string-5.4 {string length} {
  103.     list [catch {string length a b} msg] $msg
  104. } {1 {wrong # args: should be "string length string"}}
  105.  
  106. test string-6.1 {string match} {
  107.     string match abc abc
  108. } 1
  109. test string-6.2 {string match} {
  110.     string m abc abd
  111. } 0
  112. test string-6.3 {string match} {
  113.     string match ab*c abc
  114. } 1
  115. test string-6.4 {string match} {
  116.     string match ab**c abc
  117. } 1
  118. test string-6.5 {string match} {
  119.     string match ab* abcdef
  120. } 1
  121. test string-6.6 {string match} {
  122.     string match *c abc
  123. } 1
  124. test string-6.7 {string match} {
  125.     string match *3*6*9 0123456789
  126. } 1
  127. test string-6.8 {string match} {
  128.     string match *3*6*9 01234567890
  129. } 0
  130. test string-6.9 {string match} {
  131.     string match a?c abc
  132. } 1
  133. test string-6.10 {string match} {
  134.     string match a??c abc
  135. } 0
  136. test string-6.11 {string match} {
  137.     string match ?1??4???8? 0123456789
  138. } 1
  139. test string-6.12 {string match} {
  140.     string match {[abc]bc} abc
  141. } 1
  142. test string-6.13 {string match} {
  143.     string match {a[abc]c} abc
  144. } 1
  145. test string-6.14 {string match} {
  146.     string match {a[xyz]c} abc
  147. } 0
  148. test string-6.15 {string match} {
  149.     string match {12[2-7]45} 12345
  150. } 1
  151. test string-6.16 {string match} {
  152.     string match {12[ab2-4cd]45} 12345
  153. } 1
  154. test string-6.17 {string match} {
  155.     string match {12[ab2-4cd]45} 12b45
  156. } 1
  157. test string-6.18 {string match} {
  158.     string match {12[ab2-4cd]45} 12d45
  159. } 1
  160. test string-6.19 {string match} {
  161.     string match {12[ab2-4cd]45} 12145
  162. } 0
  163. test string-6.20 {string match} {
  164.     string match {12[ab2-4cd]45} 12545
  165. } 0
  166. test string-6.21 {string match} {
  167.     string match {a\*b} a*b
  168. } 1
  169. test string-6.22 {string match} {
  170.     string match {a\*b} ab
  171. } 0
  172. test string-6.23 {string match} {
  173.     string match {a\*\?\[\]\\\x} "a*?\[\]\\x"
  174. } 1
  175. test string-6.24 {string match} {
  176.     string match ** ""
  177. } 1
  178. test string-6.25 {string match} {
  179.     string match *. ""
  180. } 0
  181. test string-6.26 {string match} {
  182.     string match "" ""
  183. } 1
  184. test string-6.27 {string match} {
  185.     list [catch {string match a} msg] $msg
  186. } {1 {wrong # args: should be "string match pattern string"}}
  187. test string-6.28 {string match} {
  188.     list [catch {string match a b c} msg] $msg
  189. } {1 {wrong # args: should be "string match pattern string"}}
  190.  
  191. test string-7.1 {string range} {
  192.     string range abcdefghijklmnop 2 14
  193. } {cdefghijklmno}
  194. test string-7.2 {string range} {
  195.     string range abcdefghijklmnop 7 1000
  196. } {hijklmnop}
  197. test string-7.3 {string range} {
  198.     string range abcdefghijklmnop 10 e
  199. } {klmnop}
  200. test string-7.4 {string range} {
  201.     string range abcdefghijklmnop 10 9
  202. } {}
  203. test string-7.5 {string range} {
  204.     string range abcdefghijklmnop -3 2
  205. } {abc}
  206. test string-7.6 {string range} {
  207.     string range abcdefghijklmnop -3 -2
  208. } {}
  209. test string-7.7 {string range} {
  210.     string range abcdefghijklmnop 1000 1010
  211. } {}
  212. test string-7.8 {string range} {
  213.     string range abcdefghijklmnop -100 end
  214. } {abcdefghijklmnop}
  215. test string-7.9 {string range} {
  216.     list [catch {string range} msg] $msg
  217. } {1 {wrong # args: should be "string range string first last"}}
  218. test string-7.10 {string range} {
  219.     list [catch {string range a 1} msg] $msg
  220. } {1 {wrong # args: should be "string range string first last"}}
  221. test string-7.11 {string range} {
  222.     list [catch {string range a 1 2 3} msg] $msg
  223. } {1 {wrong # args: should be "string range string first last"}}
  224. test string-7.12 {string range} {
  225.     list [catch {string range abc abc 1} msg] $msg
  226. } {1 {expected integer but got "abc"}}
  227. test string-7.13 {string range} {
  228.     list [catch {string range abc 1 eof} msg] $msg
  229. } {1 {expected integer or "end" but got "eof"}}
  230.  
  231. test string-8.1 {string trim} {
  232.     string trim "    XYZ      "
  233. } {XYZ}
  234. test string-8.2 {string trim} {
  235.     string trim "\t\nXYZ\t\n\r\n"
  236. } {XYZ}
  237. test string-8.3 {string trim} {
  238.     string trim "  A XYZ A    "
  239. } {A XYZ A}
  240. test string-8.4 {string trim} {
  241.     string trim "XXYYZZABC XXYYZZ" ZYX
  242. } {ABC }
  243. test string-8.5 {string trim} {
  244.     string trim "    \t\r      "
  245. } {}
  246. test string-8.6 {string trim} {
  247.     string trim {abcdefg} {}
  248. } {abcdefg}
  249. test string-8.7 {string trim} {
  250.     string trim {}
  251. } {}
  252. test string-8.8 {string trim} {
  253.     string trim ABC DEF
  254. } {ABC}
  255. test string-8.9 {string trim} {
  256.     list [catch {string trim} msg] $msg
  257. } {1 {wrong # args: should be "string trim string ?chars?"}}
  258. test string-8.10 {string trim} {
  259.     list [catch {string trim a b c} msg] $msg
  260. } {1 {wrong # args: should be "string trim string ?chars?"}}
  261.  
  262. test string-9.1 {string trimleft} {
  263.     string trimleft "    XYZ      "
  264. } {XYZ      }
  265. test string-9.2 {string trimleft} {
  266.     list [catch {string triml} msg] $msg
  267. } {1 {wrong # args: should be "string trimleft string ?chars?"}}
  268.  
  269. test string-10.1 {string trimright} {
  270.     string trimright "    XYZ      "
  271. } {    XYZ}
  272. test string-10.2 {string trimright} {
  273.     string trimright "   "
  274. } {}
  275. test string-10.3 {string trimright} {
  276.     string trimright ""
  277. } {}
  278. test string-10.4 {string trimright errors} {
  279.     list [catch {string trimr} msg] $msg
  280. } {1 {wrong # args: should be "string trimright string ?chars?"}}
  281. test string-10.5 {string trimright errors} {
  282.     list [catch {string trimg a} msg] $msg
  283. } {1 {bad option "trimg": should be compare, first, index, last, length, match, range, tolower, toupper, trim, trimleft, or trimright}}
  284.  
  285. test string-11.1 {string tolower} {
  286.     string tolower ABCDeF
  287. } {abcdef}
  288. test string-11.2 {string tolower} {
  289.     string tolower "ABC  XyZ"
  290. } {abc  xyz}
  291. test string-11.3 {string tolower} {
  292.     string tolower {123#$&*()}
  293. } {123#$&*()}
  294. test string-11.4 {string tolower} {
  295.     list [catch {string tolower} msg] $msg
  296. } {1 {wrong # args: should be "string tolower string"}}
  297. test string-11.5 {string tolower} {
  298.     list [catch {string tolower a b} msg] $msg
  299. } {1 {wrong # args: should be "string tolower string"}}
  300.  
  301. test string-12.1 {string toupper} {
  302.     string toupper abCDEf
  303. } {ABCDEF}
  304. test string-12.2 {string toupper} {
  305.     string toupper "abc xYz"
  306. } {ABC XYZ}
  307. test string-12.3 {string toupper} {
  308.     string toupper {123#$&*()}
  309. } {123#$&*()}
  310. test string-12.4 {string toupper} {
  311.     list [catch {string toupper} msg] $msg
  312. } {1 {wrong # args: should be "string toupper string"}}
  313. test string-12.5 {string toupper} {
  314.     list [catch {string toupper a b} msg] $msg
  315. } {1 {wrong # args: should be "string toupper string"}}
  316.  
  317. test string-13.1 {error conditions} {
  318.     list [catch {string gorp a b} msg] $msg
  319. } {1 {bad option "gorp": should be compare, first, index, last, length, match, range, tolower, toupper, trim, trimleft, or trimright}}
  320. test string-13.2 {error conditions} {
  321.     list [catch {string} msg] $msg
  322. } {1 {wrong # args: should be "string option arg ?arg ...?"}}
  323.